//
//  BaseNavigationController.swift
//  Kool Car
//
//  Created by 鲜恬科技 on 2018/8/10.
//  Copyright © 2018年 鲜恬科技. All rights reserved.
//

import UIKit


class BaseNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.extendedLayoutIncludesOpaqueBars = false
        self.edgesForExtendedLayout = .all   
        self.navigationBar.isTranslucent = false
        self.interactivePopGestureRecognizer?.delegate = self;

        // Do any additional setup after loading the view.
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
//        print("navi viewDidAppear")
    }
    
    override var childViewControllerForStatusBarStyle: UIViewController? {
        return self.topViewController
    }
}


//MARK: - push的时候 hidden Tabbar
extension BaseNavigationController{
    override func pushViewController(_ viewController: UIViewController, animated: Bool)
    {
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            if UIApplication.shared.keyWindow?.rootViewController?.presentedViewController == nil {
                XTManageCenter.willShowTabbar(isHidden: true)
            }
        }else{
            if UIApplication.shared.keyWindow?.rootViewController?.presentedViewController == nil {
//                if !viewController.isKind(of: LoginViewController.self) {
//                    XTManageCenter.willShowTabbar(isHidden: false)
//                }
            }
        }
        self.interactivePopGestureRecognizer?.isEnabled = false
        super.pushViewController(viewController, animated: animated)
    }
}

//MARk:- 返回手势
extension BaseNavigationController : UIGestureRecognizerDelegate {
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if self.viewControllers.count <= 1 {
            return false
        }
        return true
    }
}
